<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
    function getUrl(url){
        let that = this
        // window.location.href 获取地址

        let p = url.split('?')[1]
        console.log(p)
        let keyValue = p.split('&');
        let obj = {};
        for (let i = 0; i < keyValue.length; i++) {
            let item = keyValue[i].split('=');
            obj[item[0]] = item[1];
        }

       return obj
    }

    const result = getUrl('https://xxxx.com/xxx/demo?type=1&id=2')

    console.log(result )

</script>
</body>
</html>